
"""
@名称：练习
@作者：Fida1214
@日期：2025/4/9
"""

"""
第四题，餐厅经营
"""

import random

class Dish:
    def __init__(self, name, price, cost):
        self.name = name
        self.price = price
        self.cost = cost

class Restaurant:
    def __init__(self, name, dishes):
        self.name = name
        self.dishes = dishes
        self.money = 1000

    def serve_customer(self):
        dish = random.choice(self.dishes)
        if self.money >= dish.cost:
            self.money -= dish.cost
            self.money += dish.price
            print(f"{self.name} 为顾客提供了 {dish.name}，赚了 {dish.price - dish.cost} 元。当前余额: {self.money} 元。")
        else:
            print(f"{self.name} 资金不足，无法制作 {dish.name}。")

pizza = Dish("披萨", 50, 20)
pasta = Dish("意大利面", 30, 15)

italian_restaurant = Restaurant("意大利餐厅", [pizza, pasta])

for _ in range(5):
    italian_restaurant.serve_customer()
